/***************************************************
 Defs.h

 ****************************************************/

#ifndef _defs_
#define _defs_

#define byte unsigned char
#define word short int
#define dword int

/* Flags para derechos de acceso de los segmentos */
#define ACS_PRESENT     0x80            /* segmento presente en memoria */
#define ACS_CSEG        0x18            /* segmento de codigo */
#define ACS_DSEG        0x10            /* segmento de datos */
#define ACS_READ        0x02            /* segmento de lectura */
#define ACS_WRITE       0x02            /* segmento de escritura */
#define ACS_IDT         ACS_DSEG
#define ACS_INT_386 	0x0E		/* Interrupt GATE 32 bits */
#define ACS_INT         ( ACS_PRESENT | ACS_INT_386 )

#define MAX_BUFFER_SIZE  1024
#define ACS_CODE        (ACS_PRESENT | ACS_CSEG | ACS_READ)
#define ACS_DATA        (ACS_PRESENT | ACS_DSEG | ACS_WRITE)
#define ACS_STACK       (ACS_PRESENT | ACS_DSEG | ACS_WRITE)

#pragma pack (1) 		/* Alinear las siguiente estructuras a 1 byte */

#define KERNEL_PAGES    1024
#define	HEAP_SIZE	0x1000
#define	TEMP		-2
#define NULL		0x00
#define INITIAL_PAGE	2048

/* Descriptor de segmento */
typedef struct {
	word limit, base_l;
	byte base_m, access, attribs, base_h;
} DESCR_SEG;

/* Descriptor de interrupcion */
typedef struct {
	word offset_l, selector;
	byte cero, access;
	word offset_h;
} DESCR_INT;

/* IDTR  */
typedef struct {
	word limit;
	dword base;
} IDTR;

#define MAXLINEA    160
#define MAXCOL      25
#define MAX_PROC_NAME  32

typedef struct {
	int pid;
	char nombre[MAX_PROC_NAME];
	int prioridad;
	int terminal;
	int background;
	int bloqueado;
	int padre;
	int ESP;
	int free_slot;
	int stackstart;
	int stacksize;
	int heapstart;
	int heapsize;
	int nextfree;
} process_t;

typedef struct {
	char *terminal;
	int posicion;
	unsigned char *writeBuf;
	unsigned char *readBuf;
	unsigned char buffer[MAXLINEA];
	char keyboardbuffer[MAX_BUFFER_SIZE];
	char* writepuntero;
	char* readpuntero;
} TTY;

#define CANT_PRIOR 6
#define ESPERANDO_SLEEP 1
#define ESPERANDO_HIJO  2
#define WAITING_INPUT   3
#define IDLE             7
#endif

